package com.erli.exchange.common.filter;

import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@Component
@WebFilter(urlPatterns = "/*",filterName = "commonFilter")
@Order(1)
@Slf4j
public class CommonFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("【启动成功！】");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("【有请求进来。。。。】");
//        ServletRequest requestWrapper = null;
//        log.info("我是过滤器");
//        if(request instanceof HttpServletRequest) {
//            requestWrapper = new RequestWrapper((HttpServletRequest) request);
//        }
//        if(requestWrapper == null) {
//            chain.doFilter(request, response);
//        } else {
//            chain.doFilter(requestWrapper, response);
//        }
        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {
    	log.info("【程序关闭！】");
    }
}
